package top.xiaoshuaila.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import top.xiaoshuaila.pojo.Department;
import top.xiaoshuaila.pojo.RespBean;
import top.xiaoshuaila.pojo.Salary;
import top.xiaoshuaila.service.IDepartmentService;
import top.xiaoshuaila.service.ISalaryService;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 小帅啦
 * @since 2021-05-01
 */
@RestController
@Api(tags = "工资账套管理")
@RequestMapping("/salary/sob")
public class SalaryController {
    @Autowired
    private ISalaryService salaryService;

    @ApiOperation(value = "获取所有工资帐套")
    @GetMapping("/")
    public List<Salary>getAllSalaries(){
        return salaryService.list();
    }
    @ApiOperation("添加工资账套")
    @PostMapping("/")
    public RespBean addSalary(@RequestBody Salary salary){
        if(salaryService.save(salary))
            return RespBean.success("添加成功!");
        else return RespBean.error("添加失败!");
    }
    @ApiOperation("删除工资账套")
    @DeleteMapping("/{id}")
    public RespBean deleteSalary(@PathVariable Integer id){
        if(salaryService.removeById(id))
            return RespBean.success("删除成功!");
        else return RespBean.error("删除失败!");
    }
    @ApiOperation("更新工资账套")
    @PutMapping("/")
    public RespBean updateSalary(@RequestBody Salary salary){
        if(salaryService.updateById(salary))
            return RespBean.success("更新成功!");
        else return RespBean.error("更新失败!");
    }
}
